package com.briup.corejava.day19;

import com.briup.corejava.day10.pojo.Student;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.ArrayList;
import java.util.List;

/**
 * 从object.txt中读取出Student的对象
 * ObjectInputStream
 * FileInputStream
 */
public class Test7_or {
    public static void main(String[] args) {
        ObjectInputStream ois = null;
        FileInputStream fis = null;

        try {
            fis = new FileInputStream("src/com/briup/corejava/day19/file/object.txt");
            ois = new ObjectInputStream(fis);
            Object o = ois.readObject();
            List<Student> list = new ArrayList<>();
            if(o instanceof List){
                List<?> l = (List<?>) o;
                for(Object obj : l){
                    if(obj instanceof Student){
                        Student s = (Student)obj;
                        list.add(s);
                    }
                }
            }
            System.out.println(list);

        } catch (IOException | ClassNotFoundException e) {
            throw new RuntimeException(e);
        }finally {

        }
    }
}
